package com.vf.admin.miaodong.dao;

import com.vf.admin.common.db.BaseDao;
import com.vf.admin.common.splitpage.SplitPageBean;
import com.vf.admin.miaodong.entity.GameZpRecord;
import com.vf.admin.utils.StringEx;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Repository;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * 大转盘奖励
 */
@Repository
public class GameZpRecordDao extends BaseDao<GameZpRecord> {
    private final Logger logger = LoggerFactory.getLogger(this.getClass());

    /**
     * 保存或者更新
     */
    public void save(GameZpRecord zpRecord) {
        if (zpRecord!=null && zpRecord.getId() != null && zpRecord.getId() > 0) {
            this.update(zpRecord);
        } else {
            zpRecord.setId(this.add(zpRecord));
        }
    }

    /**
     * 列表查询
     * @param paraMap
     * @param splitPage
     * @return
     */
    public List<GameZpRecord> findList(Map<String, Object> paraMap, SplitPageBean splitPage) {
        List<Object> paramList = new ArrayList<Object>();
        StringBuilder sbStr = new StringBuilder("SELECT * FROM game_zp_record WHERE 1=1");
        if (StringEx.isNotNull(paraMap.get("userid"))) {
            sbStr.append(" and userid = ? ");
            paramList.add(paraMap.get("userid"));
        }
        if (StringEx.isNotNull(paraMap.get("leixing"))) {
            sbStr.append(" and leixing = ? ");
            paramList.add(paraMap.get("leixing"));
        }
        if (StringEx.isNotNull(paraMap.get("time"))) {
            sbStr.append(" and  TO_DAYS(createtime) = TO_DAYS(NOW()) ");
        }
        sbStr.append(" order by createtime desc ");


        String sql = sbStr.toString();
        return this.queryList(sql, paramList, GameZpRecord.class, splitPage);
    }


}
